refactor(mmap): change from posix.mmap to Io.File.MemoryMap#126
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the memory mapping recipe to use the new cross-platform createMemoryMap API, enabling Windows support and removing the previous OS check. The documentation has also been updated to detail the platform-specific system calls used. Feedback suggests clearing the memory map buffer with @memset before reading to verify that data is actually read from the file, and addresses a minor typo and grammatical issue in the documentation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| // Synchronize memory with contents of file | ||
| try mm.read(io); |
There was a problem hiding this comment.
To ensure that mm.read(io) is actually reading the data from the file and not just asserting on the existing data in memory, we should clear the memory map buffer using @memset before reading.
// Clear the memory to ensure we are actually reading from the file
@memset(mm.memory, 0);
// Synchronize memory with contents of file
try mm.read(io);
There was a problem hiding this comment.
Oh Gemini, mm.write() and mm.read() are only there to make sure memory and file are synced after they are called, this does not mean, that the file contents isn't changed before .write() is called. Doing a @memset() to 0 would overwrite the text we wrote previously making the test fail...
|
Thanks for your contribution. Your changes look good to me. There’s a CI failure, but it’s not caused by your modification. Would you be able to help resolve it? If you don’t have time, I can merge this PR as is. |
|
The Chinese version is add here |
Zig has a general
MemoryMapability for files, which also supports Windows and is part of the Io interface.I changed the mmap example to use
file.createMemoryMap(). I'm not sure if the intent of the example is to specifically show the use ofmmap()in Zig, or if it should show how to do memory mapping in Zig. If it's the first one, then this change could be spun out into its own recipe with a note on the mmap description about how to do memory mapping more generally in Zig. If it's the latter, then it might still be a good idea to add a callout tostd.posix.mmap()dirctly.Also, I don't know any chinese, so I was only able to change the description of the english version.